<template>
	<view>
		<!-- 顶部 -->
		<!-- <view style="position: fixed;left: 0rpx;right: 0rpx;top: 0rpx;z-index: 100;">
			<view :style="{height:statuBarHeight+'px'}" style="background-color: #2869FE;"></view>
			<view class="cflex-r" style="background-color: #2869FE;justify-content: center;align-items: center; height: 44px;position: relative;">
				<text class="u-font-16" style="font-weight: 600;">添加项目</text>
				<view class="u-font-12" style="background-color: #FB8500;position: absolute;right: 40rpx;border-radius: 15rpx;padding: 5rpx 20rpx 5rpx 20rpx;color: #FFFFFF;">完成</view>
			</view>
		</view>
		
		<view :style="{height:statuBarHeight+44+'px'}" class="u-m-b-35"></view> -->
		
		<!-- 内容(有) -->
		<view class="u-m-b-35"></view>
		
		<view class="cflex-r u-m-t-20 u-m-l-20 u-m-r-20 u-p-20" style="background-color: #FFFFFF;" 
		v-for="(item,index) in itemList" :key="index">
			<!-- 左半部分 -->
			<view class="cflex-r" style="flex: 1;">
				<image :src="item.photo" style="width: 180rpx;height: 150rpx;border-radius:10rpx;"
				mode="aspectFill"></image>
				<view class="cflex-c u-m-l-30" style="line-height: 48rpx;">
					<view class="u-font-16" style="font-weight: bold;">
						<text>{{item.name}}</text>
						<text class="u-m-l-15" style="color: #FB8500;">￥</text>
						<text style="color: #FB8500;">{{item.price}}</text>
					</view>
					<view class="u-font-12" style="color: #A1A1A1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;width:300rpx;">{{item.itemDes}}</view>
					<view class="cflex-r u-font-12" style="align-items: center;color: #606060;">
						<image src="../../static/qieTu/shijian.png" style="width: 25rpx;height: 25rpx;"></image>
						<text class="u-m-l-5">{{item.timeSpan}}小时</text>
					</view>
				</view>
			</view>
			<!-- 右半部分 -->
			<view class="cflex-c" style="justify-content: center;align-items: center;">
				<image @tap="checkShow(index)" v-if="item.params.isChoose" src="../../static/qieTu/check.png" style="width: 30rpx;height: 30rpx;"></image>
				<image @tap="checkShow(index)" v-else src="../../static/qieTu/uncheck.png" style="width: 30rpx;height: 30rpx;"></image>
			</view>
		</view>
		
		<view style="height:200rpx;"></view><!--占位-->
		<view style="position:fixed;bottom:0;left:0;right:0;" @tap="saveItem()">
			<view class="cflex-r-c u-font-16" style="width:100%;padding:35rpx 0rpx;background-color:#2869FE;color: #fff;">完成</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				itemList:[],//项目
			}
		},
		onLoad() {
			this.httpRequest();
		},
		methods: {
			httpRequest(){//获取数据
				this.$request("worker/item/itemList",{}).then(res=>{
					this.itemList=res.data;
					this.itemList.forEach((item)=>{
						item.params.isChoose=JSON.parse(item.params.isChoose)
					})
					console.log("ite",this.itemList)
				});
			},
			saveItem(){
				let items="";
				this.itemList.forEach((item)=>{
					if(item.params.isChoose){
						items=items+item.id+",";
					}
				})
				items=items.slice(0,items.length-1);
				console.log("items===========>",items);
				if(items==''){
					return
				}else {
					this.$request("worker/item/addItem",{itemIds:items}).then(res=>{
						uni.switchTab({
							url:"../../pages/tab2"
						})
					});
				}
				
			},
			checkShow(index){
				if(this.itemList[index].params.isChoose){
					this.itemList[index].params.isChoose = false;
				}else{
					this.itemList[index].params.isChoose = true;
				}
				
			}
		},
		computed: {
			statuBarHeight(){
				return this.$store.state.sysInfo.statusBarHeight;
			}
		}
	}
</script>

<style>

</style>
